<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="权限方案名称">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="权限方案描述">
            <el-input v-model="form.description" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区区域id">
            <el-input v-model="form.nezAreaId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区区域姓名">
            <el-input v-model="form.nezAreaName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区闯入报警 1 开 2.关">
            <el-input v-model="form.nezBreakIntoAlarm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区报警等级">
            <el-input v-model="form.nezAlarmLevel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区禁入时间 1 无限制">
            <el-input v-model="form.nezNoEntryTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区禁入起始时间">
            <el-input v-model="form.nezNoEntryTimeStart" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区禁入结束时间">
            <el-input v-model="form.nezNoEntryTimeEnd" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="禁入区禁入周期 数组格式">
            <el-input v-model="form.nezCycle" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区区域id">
            <el-input v-model="form.azAreaId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区区域姓名">
            <el-input v-model="form.azAreaName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="离开报警 az_leave_alarm 滞留报警 az_delay_alarm">
            <el-input v-model="form.azAlarmType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区离开报警 1 开 2.关">
            <el-input v-model="form.azLeaveAlarm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区报警等级">
            <el-input v-model="form.azAlarmLevel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区准入时间 1 无限制">
            <el-input v-model="form.azEntryTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区准入起始时间">
            <el-input v-model="form.azEntryTimeStart" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区准入结束时间">
            <el-input v-model="form.azEntryTimeEnd" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="准入区准入时间周期  数组格式">
            <el-input v-model="form.azEntryTimeCycle" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区区域id">
            <el-input v-model="form.jzAreaId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区区域名称">
            <el-input v-model="form.jzAreaName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区离开报警 1 开 2关">
            <el-input v-model="form.jzLeaveAlarm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区离开报警报警等级 1 2 3">
            <el-input v-model="form.jzLeaveAlarmLevel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位串岗报警 1 开 2 关">
            <el-input v-model="form.jzSkewersAlarm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位串岗报警报警等级 1 2 3">
            <el-input v-model="form.jzSkewersAlarmLevel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区在岗时间 1 无限制">
            <el-input v-model="form.jzZgTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区在岗开始时间">
            <el-input v-model="form.jzZgTimeStart" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区在岗结束时间">
            <el-input v-model="form.jzZgTimeEnd" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="岗位区在岗周期 数组格式">
            <el-input v-model="form.jzZgCycle" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />

        <el-table-column prop="name" label="权限方案名称" />
        <el-table-column prop="description" label="权限方案描述" />
        <el-table-column prop="nezAreaId" label="禁入区区域id" />
        <el-table-column prop="nezAreaName" label="禁入区区域姓名" />
        <el-table-column prop="nezBreakIntoAlarm" label="禁入区闯入报警 1 开 2.关" />
        <el-table-column prop="nezAlarmLevel" label="禁入区报警等级" />
        <el-table-column prop="nezNoEntryTime" label="禁入区禁入时间 1 无限制" />
        <el-table-column prop="nezNoEntryTimeStart" label="禁入区禁入起始时间" />
        <el-table-column prop="nezNoEntryTimeEnd" label="禁入区禁入结束时间" />
        <el-table-column prop="nezCycle" label="禁入区禁入周期 数组格式" />
        <el-table-column prop="azAreaId" label="准入区区域id" />
        <el-table-column prop="azAreaName" label="准入区区域姓名" />
        <el-table-column prop="azAlarmType" label="离开报警 az_leave_alarm 滞留报警 az_delay_alarm" />
        <el-table-column prop="azLeaveAlarm" label="准入区离开报警 1 开 2.关" />
        <el-table-column prop="azAlarmLevel" label="准入区报警等级" />
        <el-table-column prop="azEntryTime" label="准入区准入时间 1 无限制" />
        <el-table-column prop="azEntryTimeStart" label="准入区准入起始时间" />
        <el-table-column prop="azEntryTimeEnd" label="准入区准入结束时间" />
        <el-table-column prop="azEntryTimeCycle" label="准入区准入时间周期  数组格式" />
        <el-table-column prop="jzAreaId" label="岗位区区域id" />
        <el-table-column prop="jzAreaName" label="岗位区区域名称" />
        <el-table-column prop="jzLeaveAlarm" label="岗位区离开报警 1 开 2关" />
        <el-table-column prop="jzLeaveAlarmLevel" label="岗位区离开报警报警等级 1 2 3" />
        <el-table-column prop="jzSkewersAlarm" label="岗位串岗报警 1 开 2 关" />
        <el-table-column prop="jzSkewersAlarmLevel" label="岗位串岗报警报警等级 1 2 3" />
        <el-table-column prop="jzZgTime" label="岗位区在岗时间 1 无限制" />
        <el-table-column prop="jzZgTimeStart" label="岗位区在岗开始时间" />
        <el-table-column prop="jzZgTimeEnd" label="岗位区在岗结束时间" />
        <el-table-column prop="jzZgCycle" label="岗位区在岗周期 数组格式" />
        <el-table-column v-permission="['admin','areaPermission:edit','areaPermission:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudAreaPermission from '@/api/system/areaPermission'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, createTime: null, updateTime: null, createBy: null, updateBy: null, name: null, description: null, nezAreaId: null, nezAreaName: null, nezBreakIntoAlarm: null, nezAlarmLevel: null, nezNoEntryTime: null, nezNoEntryTimeStart: null, nezNoEntryTimeEnd: null, nezCycle: null, azAreaId: null, azAreaName: null, azAlarmType: null, azLeaveAlarm: null, azAlarmLevel: null, azEntryTime: null, azEntryTimeStart: null, azEntryTimeEnd: null, azEntryTimeCycle: null, jzAreaId: null, jzAreaName: null, jzLeaveAlarm: null, jzLeaveAlarmLevel: null, jzSkewersAlarm: null, jzSkewersAlarmLevel: null, jzZgTime: null, jzZgTimeStart: null, jzZgTimeEnd: null, jzZgCycle: null }
export default {
  name: 'AreaPermission',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '区域权限方案', url: 'api/areaPermission', sort: 'id,desc', crudMethod: { ...crudAreaPermission }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'areaPermission:add'],
        edit: ['admin', 'areaPermission:edit'],
        del: ['admin', 'areaPermission:del']
      },
      rules: {
        createTime: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ],
        updateTime: [
          { required: true, message: '更新时间不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'name', display_name: '权限方案名称' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>

</style>
